package org.socialnetwork.rules;

import java.util.ArrayList;
import java.util.List;

import org.abac4j.annotations.AttributeFunction;
import org.abac4j.context.PostProcessor;
import org.socialnetwork.pojo.Photo;
import org.socialnetwork.pojo.Usuario;

public class RatingChecker implements PostProcessor {
	
	@AttributeFunction
	public static boolean restrictByRating(Usuario loggedUser, Usuario user){
		return true;
	}

	@Override
	public Object postProcess(Object... varargs) {
		@SuppressWarnings("unchecked") List<Photo> returnList = (List<Photo>) varargs[0];
		Object[] args = (Object[]) varargs[1];
		Usuario user = (Usuario) args[1];
		
		List<Photo> listaFotos = new ArrayList<Photo>();		
		for(Photo photo : returnList) {
			if (photo.getRating() <= user.getAge() ) {
				listaFotos.add(photo);
			}
		}
		return listaFotos;
	}
}